package com.samoiloff.util.nav {
	import flash.geom.Point;

	/**
	 * @author NM Group
	 */
	public class GameDirection {
		
		public static const RIGHT			: int = 0;
		public static const BOTTOM_RIGHT	: int = 1;
		public static const BOTTOM			: int = 2;
		public static const BOTTOM_LEFT		: int = 3;
		public static const LEFT			: int = 4;
		public static const TOP_LEFT		: int = 5;
		public static const TOP				: int = 6;
		public static const TOP_RIGHT		: int = 7;
		
		public static function getDisplacement(p:Point, dir:int, distance:int = 1):Point {
			var x:int = p.x;
			var y:int = p.y;
			switch (dir) {
				case RIGHT			: return new Point(x + distance, y); 
				case BOTTOM_RIGHT	: return new Point(x + distance, y + distance);
				case BOTTOM			: return new Point(x, y + distance);
				case BOTTOM_LEFT	: return new Point(x - distance, y + distance);
				case LEFT			: return new Point(x - distance, y);
				case TOP_LEFT		: return new Point(x - distance, y - distance);
				case TOP			: return new Point(x, y - distance);
				case TOP_RIGHT		: return new Point(x + distance, y - distance);
			}
			throw new Error("Direction is out of range : " + dir);
			return null;
		}
		
		public static function getDirByAngle(gradusAngle:Number):int {
			while (gradusAngle < 0) { gradusAngle += 360; } 
			while (gradusAngle >= 360) { gradusAngle -= 360; }
			
			var dir:int = Math.floor((gradusAngle + 22.5)/45);
			return dir%8;
		}
	}
}
